#pragma once

#include <mutex>
#include <condition_variable>

using std::mutex;
using std::condition_variable;
using std::unique_lock;

#define NUM_RESOURCE_TYPES 2

class Monitor
{
protected:
	mutex m_mtxMainMutex;

	long m_lResources[NUM_RESOURCE_TYPES];

	condition_variable m_cvOneResourceConditions[NUM_RESOURCE_TYPES];
	int m_iOneResourceConditionCounters[NUM_RESOURCE_TYPES];

	condition_variable m_cvAllResourcesCondition;
	int m_iAllResourcesConditionCounter;

	int m_iAnyConditionCounter;

	int m_iNotifiedThreadsCounter;

	int m_iLastConditionTypes[NUM_RESOURCE_TYPES + 1];

	void SaveLastConditionChoice(int conditionType);
	void SignalCondition();

public:
	Monitor();
	~Monitor();

	bool GetResource(unsigned int index);
	bool GetAllResources();
};

